const OutService = require("../service/out.service")
const ItemService = require("../service/item.service")

class OutController {
    async create(ctx,next) {
        const { name,number,categoryId,stashId,remark } = ctx.request.body
        const result = await OutService.create(name,number,categoryId,stashId,remark)
        await ItemService.create(name,-number,null,categoryId,stashId)
        ctx.body = result
    }
    async list(ctx,next) {
        const page = ctx.query.page || 1
        const pageSize = ctx.query.pageSize || 10
        const {totalCount} = await OutService.getListCount()
        const offset = (page - 1) * pageSize

        const items = await OutService.getList(pageSize,offset)

        ctx.body = {
            totalCount,
            items
        }
    }
    async remove(ctx,next) {
        const { id } = ctx.query
        const result = await OutService.remove(id)
        ctx.body = result
    }
    async itemsList(ctx,next) {
         const { stashId,categoryId } = ctx.query
         const result = await OutService.getItemsBycategoryAndStash(stashId,categoryId)
         console.log(result);
         ctx.body = result
    }
}

module.exports = new OutController()
